package com.tekj.cxqcb.view.Module.activity;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.tekj.cxqcb.MainBActivity;
import com.tekj.cxqcb.R;
import com.tekj.cxqcb.operation.BusinessDao;
import com.tekj.cxqcb.operation.resultBean.CarStoresBean;
import com.tekj.cxqcb.view.Module.activity.StoreModule.ModifyStoreAddressActivity;

import butterknife.BindView;
import butterknife.OnClick;
import common.base.activity.BaseActivity;
import common.base.operationHelper.Bean.BindingViewBean;

/**
 * 提车门店地址
 */
public class StoreAddressActivity extends BaseActivity {


    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.tv_l)
    TextView tvL;
    @BindView(R.id.ll_back)
    LinearLayout llBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_r)
    ImageView ivR;
    @BindView(R.id.tv_r)
    TextView tvR;
    @BindView(R.id.ll_right)
    LinearLayout llRight;
    @BindView(R.id.rl_title_bg)
    RelativeLayout rlTitleBg;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_default)
    TextView tvDefault;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.tv_address2)
    TextView tvAddress2;
    @BindView(R.id.tv_address3)
    TextView tvAddress3;
    @BindView(R.id.img_photo)
    ImageView imgPhoto;
    @BindView(R.id.btn_modify)
    Button btnModify;

    BusinessDao businessDao;
    CarStoresBean.DataBean dataBean;

    @Override
    public void init() {
        tvTitle.setText("提车门店地址");
        businessDao = new BusinessDao(activity, this);
        businessDao.CarStores(MainBActivity.User.getUserId());
    }

    @Override
    public int setLayout() {
        return R.layout.activity_store_address;
    }

    boolean isfirst = true;

    @Override
    public void initLoadStart() {
        if (isfirst) {
            loading.show();
        } else {
            showDialog();
        }
    }

    @Override
    public void initLoadEnd() {
        loading.dismiss();
        dialog.dismiss();
    }

    @Override
    public void initBindingView(Object mBean) {
        BindingViewBean bindingViewBean = (BindingViewBean) mBean;
        switch (bindingViewBean.getmEnumStatus()) {
            case 获取提车门店:
                CarStoresBean carStoresBean = (CarStoresBean) bindingViewBean.getBean();
                if (carStoresBean.getCode().equals("0000000")) {
                    SetViewData(carStoresBean.getData());
                }


                break;
        }

    }


    @OnClick({R.id.ll_back, R.id.btn_modify})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_back:
                finish();
                break;
            case R.id.btn_modify:
                startActivity(new Intent(activity, ModifyStoreAddressActivity.class).putExtra("data", dataBean));
                break;
        }
    }


    void SetViewData(CarStoresBean.DataBean bean) {
//        tvAddress
        dataBean = bean;
        tvName.setText(bean.getShopName());
        String address = bean.getProvinceName() + bean.getCityName() + bean.getRegionName();
        tvAddress.setText(address);
        tvAddress2.setText(bean.getAddress().replace(address, ""));
        tvAddress3.setText(bean.getHouseNumber());
        tvDefault.setText(bean.getType() == 1 ? "自己门店" : "公用门店");
        Picasso.get().load(bean.getShopImage()).into(imgPhoto);
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        businessDao.CarStores(MainBActivity.User.getUserId());
    }
}
